import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from "@angular/router";
import { UserService } from "../user.service";
@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {

  user = {
    userName: '',
    signature: '',
    email: '',
    power: '',
    icon: ''
  }
  testing = {}
  constructor(public userService: UserService, public router: Router, public actRoute: ActivatedRoute) { }
 
  ngOnInit() {
    this.actRoute.params.subscribe(
      params => {
        this.userService.getUserInfo().subscribe(data => {
          this.user.email = data.json().email;
          this.user.userName = data.json().userName;
          this.user.signature = data.json().signature;
          this.user.power = data.json().power;
          this.user.icon = data.json().icon;
          this.userService.setData(data.json());
          
          let str = "url('"+ this.user.icon+ "') no-repeat center top";
          this.testing = {
            'background': str,
            'background-size': "cover",
            '-webkit-background-size': "cover",
            '-moz-background-size': "cover",
            '-o-background-size': "cover",
            '-ms-background-size': "cover",
            'height': "100%",
            'position': "relative"
          }
        });
      }
    );
   
  }
  toChange() {
    this.router.navigate(['user/change']);
  }
  logout() {
    this.userService.logout();
    this.router.navigate(['']);
  }


}
